#include <stdio.h>
#include <string.h>

typedef struct {
    char name[256];
    char value[256];
    unsigned int offset;
} DW_AT_Entry;

typedef struct {
    char tag_name[256];
    int level;
    unsigned int offset;
    DW_AT_Entry attributes[256];
    int attribute_count;
} TagUnit;

TagUnit parseTagUnit(char lines[][1024], int start_line, int end_line) {
    TagUnit unit;
    memset(&unit, 0, sizeof(TagUnit));

    sscanf(lines[start_line], " <%d><%x>: Abbrev Number:", &unit.level, &unit.offset);
    char *tag_start = strchr(lines[start_line], '(');
    char *tag_end = strchr(lines[start_line], ')');
    strncpy(unit.tag_name, tag_start + 1, tag_end - tag_start - 1);

    for (int i = start_line + 1; i < end_line; i++) {
        if (strstr(lines[i], "DW_AT_")) {
            sscanf(lines[i], " <%x>", &unit.attributes[unit.attribute_count].offset);
            char *name_start = strstr(lines[i], "DW_AT_");
            char *name_end = strchr(name_start, ':');
            strncpy(unit.attributes[unit.attribute_count].name, name_start, name_end - name_start);
            strcpy(unit.attributes[unit.attribute_count].value, name_end + 2);
            unit.attribute_count++;
        }
    }

    return unit;
}

int main() {
    char lines[1024][1024];
    int line_count = 0;

    // Read lines from stdin
    while (fgets(lines[line_count], sizeof(lines[line_count]), stdin)) {
        line_count++;
    }

    for (int i = 0; i < line_count; i++) {
        if (strstr(lines[i], "Abbrev Number:") && !strstr(lines[i], "Abbrev Number: 0")) {
            int start_line = i;
            int end_line = i + 1;
            while (end_line < line_count && !strstr(lines[end_line], "Abbrev Number:")) {
                end_line++;
            }
            TagUnit unit = parseTagUnit(lines, start_line, end_line);
            printf("Tag: %s, Level: %d, Offset: %x\n", unit.tag_name, unit.level, unit.offset);
            for (int j = 0; j < unit.attribute_count; j++) {
                printf("  Attribute: %s, Offset: %x, Value: %s\n", unit.attributes[j].name, unit.attributes[j].offset, unit.attributes[j].value);
            }
            i = end_line - 1;
        }
    }

    return 0;
}
